<?php


namespace App\Http\Controllers\Client;
use Illuminate\Http\Request;
use App\Http\Controllers\Controller;


class AvailableBookingController extends Controller
{
    protected $redis;

    /**
     * 获取某天的可预约时间
     * @param Request $request
     * @return mixed
     */
//    public function bookingTiming(Request $request){
//        $date = $request->input('date');
//        $redis = $this->initRedis(1);
//        $availableBooking =  $redis->hGetAll($date);
//        return $this->success($availableBooking,$date."日的可预约时间获取成功");
//    }


    public function bookingTiming(Request $request){
        $date = $request->input('date');
        $store = $request->input('store');
        $redis = $this->initRedis(3);
        $availableBooking =  $redis->hGetAll($date);
        $arr=[];
        //循环所有时间点
        foreach ($availableBooking as $k=>$v){
            //循环所有的门店
            foreach (json_decode($v) as $m=>$n){
                if($m == $store){
                    $arr[$k] = $n;
                }
            }
        }
        ksort($arr);




        return $this->success($arr,$date."日的可预约时间获取成功");
    }

}
